package cn.kiliter.web.servlet;

import cn.kiliter.model.Order;
import cn.kiliter.model.User;
import cn.kiliter.serviece.OrderService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findOrderByid")
public class findOrderByidServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = (User) request.getSession().getAttribute("user");
        OrderService service=new OrderService();
        List<Order>list=service.findOrderByID(user.getId()+"");
        for (Order order : list) {
            System.out.println(order);
        }
        request.setAttribute("orders",list);
        request.setAttribute("count",list.size());
        request.getRequestDispatcher("/orderlist.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
